package it.blueocean.acanto.taglibrary.jsp.taglib.tags.datatable;

import it.blueocean.acanto.taglibrary.jsp.taglib.tags.dataset.DataSet;
import it.blueocean.acanto.taglibrary.jsp.taglib.tags.utils.HtmlPrintHelper;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DataTableTag extends BodyTagSupport
{
	private static final long serialVersionUID = 1L;

	private final static Logger logger = LoggerFactory.getLogger(DataTableTag.class);

	private String border = "";

	private String cellspacing = "0";

	private String cellpadding = "0";

	private String width = "";

	private String align = "";

	private DataSet dataset = null;

	private String htmlClass = "";

	private String style = "";

	private boolean omitTableTag = false;

	private String defaultAscImg = "";

	private String defaultDescImg = "";

	private boolean rendered = true;

	public int doStartTag() throws JspException
	{
		if(!(this.rendered))
		{
			return 0;
		}
		try
		{
			if(!(this.omitTableTag))
			{
				printOpenedTableTag();
			}
		}
		catch (IOException localIOException)
		{
			logger.error(localIOException.getMessage());
		}

	return 1;
	}

	protected void printOpenedTableTag() throws IOException
	{
		JspWriter localJspWriter = this.pageContext.getOut();
		
		HtmlPrintHelper.printOpenedHtmlStartTag("table", this.htmlClass, this.style, localJspWriter);
		
		if(!(this.border.equals("")))
		{
			HtmlPrintHelper.printAttribute("border", this.border, localJspWriter);
		}
		
		if(!(this.align.equals("")))
		{
			HtmlPrintHelper.printAttribute("align", this.align, localJspWriter);
		}
		
		HtmlPrintHelper.printAttribute("cellspacing", this.cellspacing, localJspWriter);
		HtmlPrintHelper.printAttribute("cellpadding", this.cellpadding, localJspWriter);
		
		if(!(this.width.equals("")))
		{
			HtmlPrintHelper.printAttribute("width", this.width, localJspWriter);
		}
		
		HtmlPrintHelper.printClosedHtmlStartTag(localJspWriter);
	}

	public int doAfterBody() throws JspException
	{
		if(this.rendered)
		{
			try
			{
				this.pageContext.getOut().print("</table>");
			}
			catch (IOException localIOException)
			{
				logger.error(localIOException.getMessage());
			}
		}
		
		return 6;
	}

	public int doEndTag() throws JspException
	{
		return 6;
	}

	public String getAlign()
	{
		return this.align;
	}

	public void setAlign(String paramString)
	{
		this.align = paramString;
	}

	public String getBorder()
	{
		return this.border;
	}

	public void setBorder(String paramString)
	{
		this.border = paramString;
	}

	public String getCellpadding()
	{
		return this.cellpadding;
	}

	public void setCellpadding(String paramString)
	{
		this.cellpadding = paramString;
	}

	public String getCellspacing()
	{
		return this.cellspacing;
	}

	public void setCellspacing(String paramString)
	{
		this.cellspacing = paramString;
	}

	public DataSet getDataset()
	{
		return this.dataset;
	}

	public void setDataset(DataSet paramDataSet)
	{
		this.dataset = paramDataSet;
	}

	public String getHtmlClass()
	{
		return this.htmlClass;
	}

	public void setHtmlClass(String paramString)
	{
		this.htmlClass = paramString;
	}

	public boolean isOmitTableTag()
	{
		return this.omitTableTag;
	}

	public void setOmitTableTag(boolean paramBoolean)
	{
		this.omitTableTag = paramBoolean;
	}

	public boolean isRendered()
	{
		return this.rendered;
	}

	public void setRendered(boolean paramBoolean)
	{
		this.rendered = paramBoolean;
	}

	public String getStyle()
	{
		return this.style;
	}

	public void setStyle(String paramString)
	{
		this.style = paramString;
	}

	public String getWidth()
	{
		return this.width;
	}

	public void setWidth(String paramString)
	{
		this.width = paramString;
	}

	public String getDefaultAscImg()
	{
		return this.defaultAscImg;
	}

	public void setDefaultAscImg(String paramString)
	{
		this.defaultAscImg = paramString;
	}

	public String getDefaultDescImg()
	{
		return this.defaultDescImg;
	}

	public void setDefaultDescImg(String paramString)
	{
		this.defaultDescImg = paramString;
	}
}
